﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>   
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>   
<meta http-equiv="expires" content="0"/> 
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function(){	
	//顶部导航切换
	$(".nav li a").click(function(){
		$(".nav li a.selected").removeClass("selected")
		$(this).addClass("selected");
	})	
})	

function checkFinance(){
	var hasFunction = $(".nav li a[functionId='40000']").length;
	var access = false;
	if(hasFunction > 0){
		try{
			var mData = menuData['40000']
			$.each(mData.children,function(index,child){
				if(access == true){
					return false;
				}
				$.each(child.children,function(i,grandson){
					if(grandson.functionId == '4210'){
						access = true;
						$(".nav li a[functionId='40000']").trigger("click")
						return false;
					}
				});
			});
		}catch(e){
			console.log(e.message);
		}
	}
	if(access == false){
		hasFunction = 0;
	}
	return hasFunction;
}

function checkPermission(functionId,childId){
	var hasFunction = $(".nav li a[functionId='"+functionId+"']").length;
	var access = false;
	if(hasFunction > 0){
		try{
			var mData = menuData[functionId]
			$.each(mData.children,function(index,child){
				if(access == true){
					return false;
				}
				$.each(child.children,function(i,grandson){
					if(grandson.functionId == childId){
						access = true;
						$(".nav li a[functionId='"+functionId+"']").trigger("click")
						return false;
					}
				});
			});
		}catch(e){
			console.log(e.message);
		}
	}
	if(access == false){
		hasFunction = 0;
	}
	return hasFunction;
}

</script>



</head>

<body style="background:url(images/topbg.gif) repeat-x;">

    <div class="topleft">
    <a href="main.html" target="_parent"><img src="images/eucLogo.png" title="系统首页" /></a>
    </div>
        
    <ul class="nav" id="topMenu">
    <!-- 
    <li><a href="default.html" target="rightFrame" class="selected"><img src="images/icon01.png" title="招商管理" /><h2>招商管理</h2></a></li>
    <li><a href="imgtable.html" target="rightFrame"><img src="images/icon02.png" title="模型管理" /><h2>经营管理</h2></a></li>
    <li><a href="imglist.html"  target="rightFrame"><img src="images/icon03.png" title="运营管理" /><h2>运营管理</h2></a></li>
    <li><a href="tools.html"  target="rightFrame"><img src="images/icon04.png" title="财务管理" /><h2>财务管理</h2></a></li>
    <li><a href="computer.html" target="rightFrame"><img src="images/icon05.png" title="文件管理" /><h2>智能硬件</h2></a></li>
    <li><a href="tab.html"  target="rightFrame"><img src="images/icon06.png" title="基础设置" /><h2>基础设置</h2></a></li>
    <li><a href="tab.html"  target="rightFrame"><img src="images/icon06.png" title="会员中心" /><h2>会员中心</h2></a></li>
     -->
    </ul>
            
    <div class="topright">    
    <ul>
    <!--<li><span><img src="images/help.png" title="帮助"  class="helpimg"/></span><a href="#">帮助</a></li>
    <li><a href="#">关于</a></li>-->
    <li><a href="login.html" target="_parent">退出</a></li>
    </ul>
     
    <div class="user">
    <span id="userName">admin</span>
    <i name="message" style="display:none;" onclick="readMessage()">消息</i>
    <b name="message" id="messageCount" style="display:none;" onclick="readMessage()"></b>
    </div> 
    </div>

<script type="text/javascript">
	var menuData = {};
	$(document).ready(function(){
		$.ajax({
		        url: '/euc/user/user',
		        data:'',//JSON.stringify(arr),
		        beforeSend: function(request) {
		        	var accessToken = localStorage.getItem('accessToken');
		            request.setRequestHeader("accessToken",accessToken );
		        },
		        dataType: 'JSON',
		        async: true,
		        contentType:'application/json;charset=utf-8',
		        type: 'POST',
		        success: function (data, textStatus, response) {
					$("#userName").html(data.name);
					localStorage.setItem('salsePerson',parseInt(data.id));
		        },
		        error: function () {
		        	console.log("error");
		        }
		    });
		 $.ajax({
		        url: '/euc/function/list',
		        data:'',
		        beforeSend: function(request) {
		        	var accessToken = localStorage.getItem('accessToken');
		            request.setRequestHeader("accessToken",accessToken );
		        },
		        dataType: 'JSON',
		        async: true,
		        contentType:'application/json;charset=utf-8',
		        type: 'POST',
		        success: function (datas, textStatus, response) {
					$("#topMenu").empty();
					$.each(datas,function(i,data){						
						var imageIndex = i+1;
						if(imageIndex > 6){
							imageIndex = 6;
						}
						var menu = $('<li><a functionId="'+data.functionId+'" href="'+data.action+'" target="rightFrame" class=""><h2>'+data.functionName+'</h2></a></li>');
						$(menu).appendTo($("#topMenu"));
						menuData[data.functionId] = data;
					});
					$(".nav li a").click(function(){
						$(".nav li a.selected").removeClass("selected")
						$(this).addClass("selected");
						window.parent.refreshLeft(menuData[$(this).attr('functionId')]);
					})	
					$(".nav li a").eq(0).trigger("click");
		        },
		        error: function () {
		        	console.log("error");
		        }
		});
		refreshMessage();
		setInterval ("refreshMessage()", 120000);
	});
	
	function refreshMessage(){
		$("#messageCount").html('');
		$.ajax({
	        url: '/euc/message/query/unread',
	        data:'',
	        beforeSend: function(request) {
	        	var accessToken = localStorage.getItem('accessToken');
	            request.setRequestHeader("accessToken",accessToken );
	        },
	        dataType: 'JSON',
	        async: true,
	        contentType:'application/json;charset=utf-8',
	        type: 'POST',
	        success: function (datas, textStatus, response) {
				console.log(JSON.stringify(datas));
				var messageCount = 0;
				$.each(datas,function(key,value){
					messageCount += value;
				});
				$count =parseInt($("#messageCount").text());
				if($count&&$count>0){
					$ccount = messageCount+$count;
					$("#messageCount").html($ccount);
				}else{
					$("#messageCount").html(messageCount);
				}
				if(messageCount > 0){
					$('[name="message"]').show();
				}
	        },
	        error: function () {
	        	console.log("/euc/message/query/unread error");
	        }
		});
		$.ajax({
	        url: '/euc/message/query/msg_count',
	        data:'',
	        beforeSend: function(request) {
	        	var accessToken = localStorage.getItem('accessToken');
	            request.setRequestHeader("accessToken",accessToken );
	        },
	        dataType: 'JSON',
	        async: true,
	        contentType:'application/json;charset=utf-8',
	        type: 'POST',
	        success: function (datas, textStatus, response) {
				var $mcount= parseInt(datas.data.count);
				if($mcount>0){
				$count =parseInt($("#messageCount").text());
				if($count&&$count>0){
					$ccount = $mcount+$count;
					$("#messageCount").html($ccount);
				}else{
					$("#messageCount").html($mcount);
				}

					$('[name="message"]').show();
				}
	        },
	        error: function () {
	        	console.log("/euc/message/query/unread error");
	        }
		});
	}
	
	function readMessage(){
		$(".nav li a[functionId='80000']").trigger("click")
		/*try{
			window.parent.gotoMessageNotice();
		}catch(e){
			console.log(e.message);
		}*/
	}

	

</script>
</body>
</html>
